package com.jindong.dailylearning.keypair.controller;

import com.jindong.dailylearning.keypair.utils.RSAUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/api/learn/key-pair")
@Api(value = "公钥私钥加密解密",tags = "公钥私钥加密解密")
public class KeyPairController {
    @ApiOperation(value = "加密")
    @GetMapping("encrypt")
    public String encrypt(String string) throws Exception {
        return RSAUtil.encrypt(string);
    }

    @GetMapping("dencrypt")
    @ApiOperation(value = "解密")
    public  String dencrypt(String string) throws Exception {
        return RSAUtil.dencrypt(string);
    }

    @GetMapping("getPublicKey")
    @ApiOperation(value = "获取公钥")
    public String getPublicKey() throws Exception {
        System.out.println(RSAUtil.getPublicKey("public1024.key").getEncoded());
        return RSAUtil.getPublicKey("public1024.key").toString();
    }
}
